package org.administer.contaroller;

import com.github.pagehelper.Page;
import com.github.pagehelper.PageHelper;
import org.administer.dao.CrmjiluDao;
import org.administer.pojo.CrmCustomers;
import org.administer.pojo.CrmJilu;
import org.apache.shiro.authz.annotation.RequiresPermissions;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Controller;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RequestParam;
import org.springframework.web.bind.annotation.ResponseBody;

import java.text.SimpleDateFormat;
import java.util.Date;
import java.util.HashMap;
import java.util.List;
import java.util.Map;

@Controller
@RequestMapping("/jilu")
public class JiluController {
    @Autowired
    private CrmjiluDao crmjiluDao;
//    增加
    @RequestMapping("/add")
    @ResponseBody
    public Map<String,Object> add(CrmJilu crmJilu) throws Exception{
       Map<String,Object> map=new HashMap<>();
        SimpleDateFormat sdf=new SimpleDateFormat("yyyy-MM-dd");
        String time=sdf.format(new Date());
        crmJilu.setTimer(time);
       crmjiluDao.add(crmJilu);
       return map;
    }
//    点谁的历史记录显示谁的记录
    @RequestMapping("/select")
    @ResponseBody

    public Map<String,Object> select(@RequestParam(defaultValue = "1") Integer page, @RequestParam(defaultValue = "10") Integer limit,CrmJilu crmJilu) throws Exception{
        Map<String,Object> map=new HashMap<>();
        Page<CrmJilu> pager= PageHelper.startPage(page,limit);
        List<CrmJilu> list= crmjiluDao.getlist(crmJilu);
        map.put("code",0);
        map.put("msg",null);
        map.put("data",list);
        map.put("count",pager.getTotal());
        return map;
    }
//    修改
    @RequestMapping("/update")
    @ResponseBody
    public Map<String,Object> update(CrmJilu crmJilu) throws Exception{
        Map<String,Object> map=new HashMap<>();
        SimpleDateFormat sdf=new SimpleDateFormat("yyyy-MM-dd");
        String time=sdf.format(new Date());
        crmJilu.setTimer(time);
        crmjiluDao.update(crmJilu);
        return map;
    }
//    删除交往记录
    @RequestMapping("/deleteService")
    @ResponseBody
    public Map<String, Object> delete(Integer id) throws Exception{
        Map<String,Object> map=new HashMap<>();
        crmjiluDao.del(id);
        map.put("result",true);
        return map;
    }
}
